﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.service;
using mendian;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.圣同润.Service
{
    public class 货品Service
    {
        /// <summary>
        /// 生成产品id
        /// </summary>
        /// <returns></returns>
        public static String generateGoodsId(String className)
        {
            return
                RestCall.httpGetMethod(
                    ConnectDTO.接口url + "/product/generateGoodsId?className=" + className
                );
        }
        /// <summary>
        /// 保存商品其他信息
        /// </summary>
        /// <param name="goodsNo"></param>
        /// <param name="goodsName"></param>
        /// <param name="className"></param>
        /// <param name="brandName"></param>
        /// <param name="shortName"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static String saveProductGoodsValidate(
            String goodsNo,
            String goodsName,
            String brandName,
            String shortName,
            String remark
            )
        {
            return
                RestCall.httpGetMethod(
                    ConnectDTO.接口url + "/product/saveProductGoodsValidate"
                    + "?goodsNo=" + goodsNo
                    + "&goodsName=" + goodsName
                    + "&brandName=" + brandName
                    + "&shortName=" + shortName
                    + "&remark=" + remark
                );
        }
        /// <summary>
        /// 保存商品推文
        /// </summary>
        /// <param name="goodsNo"></param>
        /// <param name="slogan"></param>
        /// <returns></returns>
        public static String saveProductSlogan(
            String goodsNo,
            String slogan
            )
        {
            return
                RestCall.PostHttp(
                    ConnectDTO.接口url + "/product/saveProductSlogan?goodsNo=" + goodsNo,
                    slogan
                    );
        }
        /// <summary>
        /// 保存规格详情
        /// </summary>
        /// <param name="goodsNo"></param>
        /// <param name="goodsDetailDTO"></param>
        /// <returns></returns>
        public static Boolean saveProductGoodsDetail(String goodsNo, GoodsDetailDTO goodsDetailDTO)
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.PostHttp(
                       ConnectDTO.接口url + "/product/saveProductGoodsDetail?goodsNo=" + goodsNo,
                       FunctionHelper.JsonSerialization(goodsDetailDTO)
                    )
                );
        }
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="goodsNo"></param>
        /// <param name="isBanner"></param>
        /// <param name="ofd"></param>
        /// <returns></returns>
        public static String saveProductBanner(String goodsNo, Boolean isBanner, OpenFileDialog ofd)
        {
            return
                FileService.UploadRequest(
                    ConnectDTO.接口url + "/product/saveProductBanner?goodsNo=" + goodsNo + "&isBanner=" + isBanner,
                    ofd.FileName,
                    Path.GetFileName(ofd.FileName),
                    "multipartFile"
                );
        }

        /// <summary>
        /// 取商品一览
        /// </summary>
        /// <returns></returns>
        public static List<GoodsFileDao> getGoodsFileAll(String className)
        {
            return
                FunctionHelper.JsonDeserialization<List<GoodsFileDao>>(
                    RestCall.httpGetMethod(
                        ConnectDTO.接口url + "/product/getGoodsFileAll?className=" + className
                        )
                    );
        }
    }

    public class GoodsFileDao
    {
        public String goodsNo { get; set; } //  货品编号
        public String goodsName { get; set; }   //  货品名称
        public String className { get; set; }   //  分类名称
        public String brandName { get; set; }   //  品牌名称
        public String shortName { get; set; }   //  货品简称
        public String remark { get; set; }   //  备注
        public List<String> productBanner { get; set; }   //  首图
        public List<String> productDetail { get; set; }   //  详情图
        public String slogan { get; set; }   //  推文
        public Dictionary<String, GoodsDetailDTO> goodsDetailDTOList { get; set; } = new Dictionary<String, GoodsDetailDTO>();   //  规格详情
        public Boolean isValidate { get; set; } //  是否生效
        public DateTime createDate { get; set; }
        public GoodsFileDao()
        {

        }
    }
    public class GoodsDetailDTO
    {
        public String specNo { get; set; }  //  商家编码
        public String specName { get; set; }    //  规格名称
        public Double lowestPrice { get; set; } //  最低价
        public Double retailPrice { get; set; } //  零售价
        public Double wholesalePrice { get; set; }  //  批发价
        public Double memberPrice { get; set; }//  会员价
        public Double marketPrice { get; set; } //  市场价
        public Boolean isLoweCost { get; set; } //  允许低于成本
        public String imgUrl { get; set; }  //  图片链接
        public String remark { get; set; }  //  单品备注
        public String taxCode { get; set; } //  税务编码
        public GoodsDetailDTO(string specNo, string specName, double lowestPrice, double retailPrice, double wholesalePrice, double memberPrice, double marketPrice, bool isLoweCost, string imgUrl, string remark, string taxCode)
        {
            this.specNo = specNo;
            this.specName = specName;
            this.lowestPrice = lowestPrice;
            this.retailPrice = retailPrice;
            this.wholesalePrice = wholesalePrice;
            this.memberPrice = memberPrice;
            this.marketPrice = marketPrice;
            this.isLoweCost = isLoweCost;
            this.imgUrl = imgUrl;
            this.remark = remark;
            this.taxCode = taxCode;
        }
    }
}
